home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / EDITORS / ZAP130 / !Zap / Docs / Redraw < prev   
Text File  |  1995-03-30  |  38KB  |  870 lines

  1. *************************************************************************
  2. * >Redraw - Documentation for the ZapRedraw module v0.22        *
  3. *************************************************************************
  4.  
  5. Summary:
  6. --------
  7.  
  8. The module ZapRedraw provides the "ZapRedraw_" SWI's which are capable of
  9. drawing a rectangle of text characters on screen. It offers the following
  10. features:
  11.  
  12. * Redraw may be by direct screen access (henceforth DSA) where the
  13.   data is poked into the screen memory or by the standard VDU redraw.
  14.   
  15. * Full colour provided (with your own definable palette). Supports up to 32
  16.   bits per pixel in DSA mode and 24 bit colour in VDU mode.
  17.  
  18. * DSA redraw can handle any size of bitmap characters. Special optimised
  19.   code is provided for 8 pixel wide characters in all modes.
  20.   Also 8*8 and 8*16 character sizes are given priority.
  21.   Up to 65536 characters can be defined.
  22.   
  23. * VDU redraw mode can handle any font and font size.
  24.  
  25. * Support is provided for cursors.
  26.  
  27. * Many extra SWIs perform all the work of creating cached bitmaps, updating
  28.   them on a mode change etc. Swi's are also provided for creating palettes
  29.   and other functions related to the redraw.
  30.  
  31. * An example program is provided which can be used as a template.
  32.   
  33. Limitations:
  34.  
  35. * All characters are equally spaced. Proportional spacing is not supported.
  36.  
  37. Copyright:
  38. ----------
  39.  
  40. The ZapRedraw module is copyright Dominic Symes 1994. Please contact me if
  41. you wish to use it in a program other than Zap. See the Zap Copyright file
  42. for my address.
  43.  
  44. Definitions required for the SWI's
  45. ==================================
  46.  
  47. ZapRedraw chunk prefix: ZapRedraw
  48. ZapRedraw chunk number: &48480
  49.  
  50. All SWI numbers below are given as offsets from the chunk number.
  51.  
  52. 'DSA' means direct screen access mode (characters poked into the screen).
  53. 'VDU' means VDU mode (operating system called to draw characters).
  54.  
  55. Pixel co-ordinates are used wherever possible to prevent rounding errors when
  56. OS co-ordinates are not pixel aligned (these errors DO mess things up!).
  57. Pixel co-ordinates are from the top left of the screen with the y axis
  58. descending. By a 'pixel' I mean a hardware pixel (this differs from an OS
  59. pixel in double-pixel emulation modes - this only crops up in the RISC OS 2
  60. MODE 2 wimp!).
  61.  
  62. Zap redraw block:
  63. -----------------
  64.  
  65. For several SWI's, R1 points to a redraw block of the type described below.
  66. The SWI documentation will mention which data in the block is actually used
  67. by that SWI (so should be filled in). Each offset in the block is named with
  68. a name beginning 'r_'. The Basic program E-Library contains a procedure to
  69. set these variables up should you be using the Basic assembler. The contents
  70. of some offsets depends on which redraw mode is being used (VDU or DSA), this
  71. is indicated by 'VDU:' and 'DSA:'.
  72.  
  73. Offset    Name        Function
  74.  
  75. &00    r_flags        Flags word determining the type of redraw:
  76.             b0 Clear for DSA mode. Set for VDU redraw mode.
  77.             b1 Set for 'double height mode'. Only valid in DSA
  78.                mode. Draws each raster twice so actual character
  79.                height is 2*r_charh and spacing 2*r_linesp.
  80.             b2 Extension routine provided.
  81.                Only valid in DSA mode. See ZapRedraw_RedrawArea.
  82.             b3-31 Reserved - set to zero.
  83. &04    r_minx        Min x of redraw (pixels from lhs - inclusive)
  84. &08    r_miny        Min y of redraw (pixels from top - inclusive)
  85. &0C    r_maxx        Max x of redraw (pixels form lhs - exclusive)
  86. &10    r_maxy        Max y of redraw (pixels from top - exclusive)
  87. &14    r_screen    DSA: Address of screen to write to or 0 to read the
  88.                  current screen address.
  89.             VDU: ignored
  90. &18    r_bpl        DSA: Bytes per raster line of the screen
  91.             VDU: ignored
  92. &1C    r_bpp        Log base 2 of number of bits per pixel
  93.             (ie 0=2 cols 1=4 cols 2=16 cols 3=256 cols
  94.             4=65536 cols 5=2^32 cols).
  95. &20    r_charw        Width of a character in pixels
  96. &24    r_charh        Height of a character in pixels
  97. &28    r_caddr        DSA: Address of character cache (format below)
  98.             VDU: Pointer to font name or 0 for system font
  99. &2C    r_cbpl        DSA: Number of bytes per cached character line.
  100.             VDU: x os offset of where to print the font char
  101.                  in the character 'box'. (eg 0 for system font)
  102. &30    r_cbpc        DSA: Number of bytes per cached character.
  103.             VDU: y os offset of where to print the font char
  104.                  in the character 'box'. (eg char height-1 for
  105.                  system font as VDU5 plots char downwards).
  106. &34    r_linesp    Line spacing in pixels.
  107. &38    r_data        Address of data (rectangle of characters) to print
  108.             on the screen (format below).
  109. &3C    r_scrollx    Horizontal scroll offset in rectangle of characters
  110.             given in r_data of top left of redraw rectangle.
  111.             This is in pixels from the lhs of the characters.
  112.             Thus it equals n*r_charw+m where n is the number of
  113.             characters in and m is the number of pixels into
  114.             the n'th character.
  115. &40    r_scrolly    Vertical scroll offset in rectangle of characters
  116.             given in r_data of top left of redraw rectangle.
  117.             This is in pixels from the top of the characters.
  118.             Note that in single height mode each line is
  119.             r_charh+r_linesp pixels high and in double height
  120.             mode each line is 2*(r_charh+r_linesp) pixels high.
  121. &44    r_palette    Address of palette to be used for colour translation.
  122.             (see below).
  123. &48    r_for        Foreground colour to use at the start of a line as an
  124.             offset in the palette table.
  125. &4C    r_bac        Background colour to use at the start of a line as
  126.             an offset in the palette table.
  127. &50    r_workarea    Pointer to an area of workspace for the SWI to use.
  128.             The size of this workspace depends on the SWI.
  129.             (It must be word aligned).
  130. &54    r_magx        Log base 2 of number of x os co-ords per pixel.
  131. &58    r_magy      Log base 2 of number of y os co-ords per pixel.
  132. &5C    r_xsize        Width of screen in pixels.
  133. &60    r_ysize        Height of screen in pixels.
  134. &64    r_mode        Current screen mode.
  135.  
  136. Character cache format (r_caddr):
  137. ---------------------------------
  138.  
  139. When using VDU redraw, this should point to the name of the font to use, or
  140. be zero for the system font.
  141.  
  142. When using direct screen access, the module will expect this block to contain
  143. the bitmaps for all the characters it is asked to print. Each character has
  144. size r_cbpc so it will expect to find the bitmap for ascii character 'n' at
  145. address char_start=(!r_caddr)+n*r_cbpc. The character definition then
  146. consists of r_charh rows of r_cbpl each so r_cbpc=r_charh*r_cbpl. NB r_cbpl
  147. need not be a multiple of 4 so this address need not be word aligned.
  148.  
  149. The format of a row is the same of that for a sprite file except there is
  150. never any lhs wastage. Ie, the first pixel is aligned to the start of the
  151. first word. Each character is r_charw pixels wide and thus requires
  152. N=r_charw<<r_bpp bits of storage. There are special cases when N is small:
  153.  
  154.  If 0<N=<8  then r_cbpl=1 and the top 8-N bits of each byte are wasted.
  155.  If 8<N=<16 then r_cbpl=2 and the top 16-N bits of each byte are wasted.
  156.  If N>16    then r_cbpl is aligned to the next multiple of 4 bytes greater
  157.   or equal to N. (eg 16<N=<32 => r_cbpl=4, 32<N=<64 => r_cbpl=8 etc).
  158.   
  159. The SWI ZapRedraw_CachedCharSize will calculate the values of r_cbpl and
  160. r_cbpc for you from a given size of character.
  161.  
  162. Only TWO colours can be used in the defn of the character. Set all foreground
  163. pixels to 1's and background pixels to 0's. Eg, in a 16 colour mode pixels
  164. will be either 1111 or 0000. Unused bits at the end of the words (or bytes)
  165. are ignored and so can contain rubbish. The real foreground and background
  166. colours are masked in at run time.
  167.  
  168.  Examples:
  169.  
  170.  For 8*8 characters at 1 bit per pixel we have 1 byte per row. Eg "E" may be
  171.  cached as:
  172.                   b0 .. b7
  173.       row0    &7E        01111110
  174.     row1    &06        01100000
  175.       row2    &06        01100000
  176.       row3    &7E        01111110
  177.       row4    &06        01100000
  178.       row5    &06        01100000
  179.       row6    &7E        01111110
  180.       row7    &00        00000000
  181.  
  182.  If it was in a 16 colour mode then there would be one word per row and the
  183.  first rows would be:
  184.                  b0 ......................... b31
  185.      row0    &01111110    00001111111111111111111111110000
  186.      row1    &00000110    00001111111100000000000000000000
  187.      ...
  188.       
  189.  In general you have:
  190.  
  191.      Word 0                    Word (N/4)-1
  192.      b0 .... b31    ...................      b0 ..... b31
  193.      pix0 pix1 ......................pix(r_charw-1) 00000
  194.      
  195. In practice you first cache the font at one bit per pixel (eg use
  196. ZapRedraw_ReadSystemChars) and then convert it to 'n' bits per pixel (for the
  197. current mode) by use of ZapRedraw_ConvertBitmap.
  198.  
  199. Although I have said that the foreground colour must be all 1's and the
  200. background all 0's this is not strictly true. The data poked into the screen
  201. memory is (foreground mask AND bitmap) OR (background mask BIC bitmap). Thus
  202. if you have a foreground mask of &FFFFFFFF and a background mask of 0 then
  203. the bitmap will be poked directly into the screen so can have any format you
  204. like (though character merging and several other features may not work
  205. properly). This idea can be used in conjunction with ZapRedraw_CacheFontChars
  206. to create a fast redraw mode for anti aliased fonts (as used in Zap).
  207.  
  208. Format of text to display (r_data):
  209. -----------------------------------
  210.  
  211. This block contains the text to be printed on the screen. There should be
  212. sufficient text here to redraw the specified area of the screen (given its
  213. size, the scroll offset, character sizes etc). Terminating each line with
  214. the bytes 0,2 will ensure the redraw doesn't run out of text horizontally and
  215. terminating the line list with a zero will ensure the same vertically. The
  216. value in r_data points to a list of words. The n'th word in the list is the
  217. offset (from the block data start) of the n'th line of text to be printed in
  218. the window. This list can be terminated by a 0 offset in which case all
  219. further lines will be cleared to background colour (r_bac).
  220.  
  221. The data for each line consists of a string of bytes giving the characters to
  222. print. By character number 'n' will I mean the n'th (n starting from 0)
  223. bitmap in your character cache in DSA mode or the character with ASCII code
  224. 'n' in VDU redraw mode. The Redraw module does not limit n to the range 0-255
  225. but also allows higher values. Currently you can access 0-65535. Of course,
  226. ASCII characters for the codes 0-31 and 256-65535 are not defined. Zap treats
  227. these specially - see below.
  228.  
  229. The byte 0 in the data for a line introduces a control code. Bytes 1-255 just
  230. print characters n=1-255 as normal so you will need to use control codes to
  231. access characters > 256. The currently defined control sequences are:
  232.  
  233.  0,0        Prints character n=0.
  234.  0,1,f,b    Switch colour to foreground f and background b. (f/b are
  235.         palette offsets - see r_for/r_bac).
  236.  0,2        End of line - the rest of the line is cleared to the current
  237.          background colour.
  238.  0,3,l,h    Print character n=l+h*256.
  239.  0,4,f,b,x,y    Merges the characters x,y. If a pixel is clear in the bitmap
  240.         for y then the pixel is drawn according to the bitmap for x
  241.         and the current for/background colours. If the pixel is
  242.         set for y then the colours f/b are used instead for the x
  243.         pixel. Useful for laying a cursor on top of the character.
  244.         This effect is simulated in VDU mode by using sprites and
  245.         masks. This leaves the current foreground and background
  246.         colours unaltered. NB x and y may contain control codes as
  247.         well. Eg you could have x=0,0 and y=0,3,0,1. If you nest,
  248.         0,4 codes (ie either x or y contain 0,4) then only the most
  249.         deeply nested one will have effect.
  250.  0,5        For internal use only. Restores the stacked values after a
  251.          0,4 call. Putting this in your input string will probably
  252.          cause a crash.
  253.  0,6,f        Change foreground colour to f.
  254.  0,7,b        Change background colour to b.
  255.  0,8,f,b,x,y    Cursor merge of characters x,y. This is similar to 0,4 but
  256.          only works for characters &7F,&100-&105. For &7F, it masks
  257.          in the block simply by changing the for/bac cols of the
  258.          current character being printed. For &100+, the square or
  259.          line is plotted over the top of the character in the
  260.          background colour b.
  261.  
  262. Note that sequences with codes 0,3,4 evaluate to one 'screen printable
  263. character', code 1 to none, and code 2 to as many as is required. Thus it is
  264. not a simple matter to calculate the start of the n'th actual printable
  265. character given a string containing control codes as above. The SWI
  266. ZapRedraw_FindCharacter does this for you.
  267.  
  268. In DSA mode character 'n' just looks up the cached character at address
  269. r_caddr+n*r_cbpc. Usually the bitmaps will correspond to the VDU list
  270. below so that character &20 will be the bitmap for a space etc.
  271.  
  272. In VDU mode character 'n' is interpreted as below:
  273.  
  274.   &00        Prints a '0' (ASCII &30)
  275.   &01-&1A    These print the letters A-Z (ie &40 is added)
  276.   &1B-&1F    Prints "[ \ ] ^ _" respectively (ie &40 is added)
  277.   &20-&7E    Usual Ascii characters printed.
  278.   &7F        This draws a filled in block (useful for a cursor)
  279.   &80-&FF    Usual Ascii characters printed.
  280.   &100        This draws the top,bottom,left edges ie '['.
  281.   &101        This draws the top,bottom edges.
  282.   &102        This draws the top,bottom,right edges ie ']'.
  283.   &103        This draws an empty square (useful for a cursor)
  284.   &104        This draws the baseline ie '_' (useful for a cursor)
  285.   &105        This draws the left edge giving a vertical bar.
  286.   &106+        Undefined action (prints an @ for debugging purposes)
  287.           (More codes may be added in future).
  288.   
  289. The characters are drawn using OS_WriteN/OS_WriteC/OS_Plot (or Font_Paint if
  290. not using the system font).
  291.  
  292. Use ZapRedraw_FindCharacter to jump over the control codes. Use
  293. ZapRedraw_PrepareDataLine to automatically generate the r_data lines from
  294. normal text with foreground and background colour masks. Use
  295. ZapRedraw_AddVduBitmaps to create the bitmaps for character codes 0-&1F,&7F
  296. and >=&100.
  297.  
  298. Format of palette data (r_palette):
  299. -----------------------------------
  300.  
  301. All colours are specified as offsets in the palette table. Thus if you set
  302. r_for to 1 then the module will look up the word at offset 4*1 in the palette
  303. table when it comes to printing a character.
  304.  
  305. DSA MODE: The palette consists of a list of words giving the colour 'mask' to
  306. use for this colour. The mask is duplicated to fill the word out. For
  307. example, in a 16 colour mode, the mask &AAAAAAAA would stand for actual
  308. screen colour 10. The table:
  309.  
  310.         &33333333
  311.         &66666666
  312.         &AAAAAAAA
  313.         &00000000
  314.         
  315. would cause 3 to be poked into the screen when in zap colour 0, 6 when in
  316. zap colour 1 etc. The masks will usually correspond to the wimp colours. The
  317. SWI ZapRedraw_CreatePalette is provided to set them up.
  318.  
  319. The actual value poked into the screen is: (Foreground mask AND bitmap) OR
  320. (Background mask BIC bitmap) where the bitmap is as specified in r_caddr.
  321.  
  322. VDU MODE: The palette consists of a list of words giving the 24 bit colour
  323. required. The word is in the form of a standard palette entry. Ie, &BBGGRRxx
  324. where &BB is the amount of blue etc. These will usually be set up by reading
  325. the wimp palette. The SWI ZapRedraw_CreatePalette will do this for you.
  326. ColourTrans calls will be used during the redraw to find the closest
  327. available GCOL colour.
  328.  
  329. *****************************************************************
  330. * SWI Definitions                        *
  331. *****************************************************************
  332.  
  333. None of the SWI's are re-entrant unless explicitly mentioned. All the SWI's
  334. corrupt R0 and flags and can produce errors.
  335.  
  336. ZapRedraw_RedrawArea (+&00)
  337. ---------------------------
  338.  
  339. This redraws a rectangle of characters on the screen.
  340.  
  341. Entry:    R1=redraw block (as described above).
  342.     All defined offsets in the redraw block are used.
  343.     
  344.     In VDU mode r_workarea must be at least 64 bytes+the amount needed
  345.      for a sprite of one character - see ZapRedraw_SpriteSize.
  346.      If using fonts then the first word of the workarea should contain
  347.      the fontsize in points.
  348.     
  349.     In DSA mode r_workarea must be at least 64+r_cbpl bytes (and a
  350.      whole number of words long).
  351.      If b2 of the r_flags word is set then you provide an extension
  352.      routine and:
  353.       R2=address of the routine
  354.       R3=private word value to pass to the routine.
  355.  
  356. Exit:    R0 and flags corrupted.
  357.  
  358. The extension routine is provided so you can trap unknown control codes and
  359. add extra functionality to the ones that exist. For example, you may wish to
  360. change font on a colour change. Zaps fast font redraw mode does this. If you
  361. provide an extension routine then on entry to it R0=reason code R12=your
  362. private word and:
  363.  
  364.  R0=0 => Starting a raster line:
  365.       R1=redraw block
  366.       R3=address of first character
  367.       R4=r_caddr+r_cbpl*row where row (0 ... r_charh-1) is the current
  368.          character row being drawn. Or, R4=0 if in line spacing.
  369.       R5=screen address of current word being written
  370.       R6=bit offset in current word being written
  371.       R7=current word being writen (bits >= R6 are clear)
  372.       R10=start foreground mask (eg &77777777)
  373.       R11=start background mask (eg &00000000)
  374.       
  375.  R0=1 => Foreground and background colours changing (control code 0,1)
  376.       Registers as above with R3=next character after the control
  377.       code and R10,R11 new foreground/background masks etc.
  378.  
  379.  R0=4 => About to merge characters (control code 0,4)
  380.       R1=redraw block
  381.       R2=character defn table to use for the mask character
  382.       R3=next character after the merge
  383.       R4=character defn table for the base character (as for R0=1)
  384.       R6=base char
  385.       R7=mask char (or these are -1 if invalid).
  386.       R8/R9=for/bac masks where mask character bits set.
  387.       R10/R11=current for/bac masks.
  388.       NB Any changes you make to these registers will be effective for
  389.       this one character only the normal values being stacked.
  390.  
  391.  R0=6 => Foreground colour changing (control code 0,6)
  392.       Registers as for R0=1.
  393.  
  394.  R0=7 => Background colour changing (control code 0,7)
  395.       Registers as for R0=1.
  396.       
  397.  R0=8 => About to cursor merge characters (control code 0,8)
  398.       Registers as for R0=4
  399.       If R7<&100 then R10/R11 will be set to R9/R8 and next char drawn
  400.       If R7>=&100 then the characters will be merged with R9
  401.       copied into R8.
  402.  
  403.  R0=2,3,5,>8     Reserved - ignore.
  404.  
  405.  Exit:  You may corrupt R0 and R12 and alter the registers mentioned
  406.       (except R1!) to new (sensible) values.
  407.       All registers are reset at the start of a new raster line.
  408.       You must not alter the redraw block itself.
  409.     You CANNOT return errors from an extension call.
  410.  
  411. ZapRedraw_GetPaletteEntry (+&01)
  412. --------------------------------
  413.  
  414. This SWI takes a colour bitmap and duplicates it to fill a word, creating
  415. a mask as needed for r_palette in DSA mode. Eg if R0=7 and R1=2 on entry then
  416. R0=&77777777 on exit.
  417.  
  418. Entry:    R0=The colour number to be poked into the screen. (0->num_of_cols-1)
  419.     R1=r_bpp (0-5)
  420.  
  421. Exit:    R0=Mask to put in palette table (with colour duplicated to fill the
  422.     word).
  423.  
  424. ZapRedraw_RedrawRaster (+&02)
  425. -----------------------------
  426.  
  427. Redraws a single raster line. Only applies to non-vdu redraw. This is a low
  428. level call used by ZapRedraw_RedrawArea and not of much use otherwise.
  429.  
  430. Entry:    R1=redraw block
  431.            Offsets used are: r_flags,r_minx,r_maxx,r_bpp,r_charw,r_charh
  432.             r_cbpl,r_cbpc,r_palette,r_workarea.
  433.     R3=address of text to use for this line starting at the first
  434.        visible character.
  435.     R4=address of character defn table with row offset added so redraw
  436.        uses first 'row' of each bitmap, or set to 0 if you want the
  437.        line to be cleared to the background colour (eg interline gap).
  438.     R5=screen address of the start of the raster line.
  439.     R6=b0-b15    = start foreground colour to use (eg r_for value)
  440.        b16-b31    = start background colour to use (eg r_bac value)
  441.     The initial words of r_workarea are set up as follows:
  442.     #0 Pixel scroll offset within the first visible char (0->charw-1)
  443.     #4 Number of pixels to do from the first character   (0->charw-1)
  444.     #8 Number of whole characters to do after the first char
  445.     #12 Number of pixels to do in the last visible char  (0->charw-1)
  446.     #16 -
  447.     #20 Address of extension sub if redraw flags bit 2 set
  448.     #24 Extension sub private word pointer redraw flags bit 2 set
  449.             
  450. Exit:    R0 and flags corrupted.
  451.  
  452. ZapRedraw_ConvertBitmap (+&03)
  453. ------------------------------
  454.  
  455. This SWI takes a character bitmap of the form of 1 bit per pixel, (the bit
  456. set for foreground/clear for background) and converts it into a bitmap for
  457. use by the RedrawArea SWI, by changing each '1' to n '1's and each '0' to
  458. n '0's where 'n' is the number of bits per pixel given. It uses the SWI
  459. ZapRedraw_ConvBitmapChar to do this.
  460.  
  461. Entry:    R1=redraw block, offsets looked at are:
  462.     r_bpp        To find the number of bits per pixel.
  463.     r_charw        Width of char in pixels
  464.     r_charh        Height of char in pixels
  465.     r_caddr        Address to write the bitmap. Memory at offsets
  466.             R2*r_cbpc to (R3+1)*r_bpc must be preserved
  467.     r_cbpl        Cache line width in bytes (as defined under
  468.             r_caddr help text)
  469.     r_cbpc        Number of bytes per cached character (as defined
  470.             under r_caddr help text)
  471.     R2=First character to be converted (eg 0)
  472.     R3=Last character to be converted (inclusive) (eg 255)
  473.     R4=Address of source bitmap of the format described under r_caddr
  474.        but with 1 bit per pixel (ie 2 colour mode format)
  475.  
  476. Exit:    r_caddr block written to.
  477.     R0 and flags corrupted.
  478.  
  479. ZapRedraw_PrepareDataLine (+&04)
  480. --------------------------------
  481.  
  482. This SWI is to help prepare the 'r_data' field of the redraw block. It takes
  483. as input the pointer to a line of text character (0-255) to be treated as
  484. ordinary characters (0 is not a control code). It also takes as input a
  485. pointer to a background mask and a foreground mask list, giving the
  486. background and foreground colours of each character separately. The output is
  487. a line of the format required by 'r_data' with control codes changing the
  488. colours and specifying the line end. Control codes in the input string can
  489. have their colour set automatically by setting R0 to the colour.
  490.  
  491. Eg: Input:
  492.  
  493.     Text input (characters): "HELLO WORLD         "
  494.     Foreground (bytes list):  11111122222222222222
  495.     Background (bytes list):  00000000000000000000
  496.     Start background 0
  497.     Start foreground 1
  498.     Input length 20
  499.         
  500.     Output: "HELLO ",0,1,2,0,"WORLD",0,2 (highest letter used = "W").
  501.     
  502. Entry:    R0=foreground colour to use for control characters (0-&1F) or
  503.        set to -1 if you do not wish ctrl chars to be specially treated.
  504.     R1=redraw block giving start foreground background colours in
  505.        r_for,r_bac - nothing else used.
  506.     R2=pointer to text input string (length in R5)
  507.     R3=pointer to foreground mask (length in R5)
  508.     R4=pointer to background mask (length in R5)
  509.     R5=length of inputs in bytes
  510.     R6=destination buffer (length must be at least 6*R5+16 to ensure
  511.        it is big enough - colour change + 0 -> 0,0 + terminator).
  512.        
  513. Exit:    R0=highest used character code used (ie &20-&FF). You may not
  514.     want to cache all font characters as usually those >= 128 are not
  515.     needed. This tells you the range you MUST cache.
  516.     R5=length of output string (including 0,2 terminator)
  517.     Only the codes 0,0 (for byte 0) 0,1 (for change colour) 0,2 (line
  518.     end) are used.
  519.  
  520. ZapRedraw_AddCursor (+&05)
  521. --------------------------
  522.  
  523. This SWI takes a line of the same format used in 'r_data', eg the output from
  524. the above SWI, and adds in the codes to place 'cursors' over some of the text
  525. by using the code 0,4 (merge characters) or the code 0,8 (merge cursors).
  526. Here, a cursor means a string of characters to be overlayed.
  527.  
  528.  Entry:    R0=destination string
  529.      R1=redraw block giving initial r_for and r_bac.
  530.      R2=offset in source string of first character to be in the cursor
  531.     R3=cursor length (length in characters of string pointed to by R4)
  532.     R4=pointer to string of cursor characters (usually &7Fs)
  533.     R5=source string (0,2 terminated)
  534.     R6=swap colour/-1 if none. If the character having the cursor placed
  535.        over it has this foreground colour then the cursor bac/foreground
  536.        cols are swapped over (eg in a selected region).
  537.     R7=b0-b7   high byte to use for cursor characters in R4 string
  538.        b8-b15  control code to use when merging ie 4 or 8.
  539.        b16-b23 foreground colour of the cursor
  540.        b24-b31 background colour of the cursor
  541.     Room should be reserved for the string to grow by 8*R3
  542.     characters. (eg 0,4,f,b,old,0,3,l,h) If the indicated offset (R2)
  543.     is off the end of the string then it will be lengthened with spaces
  544.     (&20) so you should ensure R2+9*R3 characters extra are reserved.
  545.     
  546.  Exit:    R0=end of new destination string (after 0,2 terminator)
  547.  
  548. ZapRedraw_FindCharacter (+&06)
  549. ------------------------------
  550.  
  551. This SWI takes as input a line of the format required by 'r_data' (ie
  552. containing ctrl sequences starting with 0) and a number 'n' and returns the
  553. start of the (n+1)'th printable character within this line (ie it skips over
  554. n printable characters), ignoring colour change control codes etc. Thus on
  555. exit it points to a byte 1-255 or one of the control sequences 0,0 or 0,2 or
  556. 0,3,l,h or 0,4,f,b,c1,c2 each of which define one printable character. If the
  557. offset n is off the end of the line then it will point to the 0,2 terminator.
  558. It also keeps track of the colour changes that take place. NB If n=0 then it
  559. may still be useful - as it will jump over any colour changes before the
  560. first character. If R0>R1 on exit then the character was found, otherwise
  561. there were R1-R0 characters left to skip.
  562.  
  563. Eg: Input:    "hello ",0,1,2,3,"goodbye",0,2
  564.     Output:    If n=0 then it will point to the 'h'
  565.             If n=6 then it will point to the 'g'
  566.             If n=100 then it will point to the 0 of 0,2.
  567.  
  568.  Entry:        R0=n (number of characters to skip)
  569.               (or -1 to move to the end of the string - find its len)
  570.         R1=pointer to the input string (terminated by 0,2)
  571.          R2=current foreground colour
  572.          R3=current background colour
  573.          
  574.  Exit:        R0=If the n'th character is in the string then this points
  575.              to the end of the n'th character (start in R1)
  576.             If the n'th 'character' is the terminator (0,2) then this
  577.              equals R1 (start of the terminator)
  578.             If it reached the string terminator before the n'th
  579.              character then this is R1-number of chars not skipped
  580.          R1=start of the next printable character after skipping n.
  581.             (or string terminator if reached that first).
  582.          R2-R3 updated by any colour change control codes.
  583.          Flags corrupted.
  584.             
  585. ZapRedraw_MoveBytes (+&07)
  586. --------------------------
  587.  
  588. This is a fast byte shifting SWI. Highly optimised and bytes are shifted
  589. starting at the top or bottom depending on whether the destination address is
  590. higher or lower than the start (respectively). Thus the data is always
  591. preserved.
  592.  
  593.  Entry:        R1=source address (need not be word aligned)
  594.          R2=destination address (need not be word aligned)
  595.          R3=number of bytes to move (>=0)
  596.  
  597.  Exit:        R0-R3 and flags corrupted.
  598.  
  599. ZapRedraw_CachedCharSize (+&08)
  600. -------------------------------
  601.  
  602. This SWI works out the values of r_cbpl,r_cbpc from r_charw,r_charh,r_bpp in
  603. the manner defined under the help text on r_caddr. Ie, r_cbpl is either 1,2,
  604. or a multiple of 4 and r_cbpc=r_charh*r_cbpl.
  605.  
  606.  Entry:        R0=r_bpp value
  607.          R2=r_charw value
  608.          R3=r_charh value
  609.          
  610.  Exit:        R2=number of bytes per cache line (r_cbpl)
  611.          R3=number of bytes per cached character (r_cbpc)
  612.  
  613. ZapRedraw_ConvBitmapChar (+&09)
  614. -------------------------------
  615.  
  616. This SWI is for the use of the ConvertBitmap SWI and performs the bitmap
  617. conversion for one character. It takes a bit map of the one bit per pixel
  618. format and expands it to have n=2^R7 bits per pixel by replacing each '0'
  619. with n '0's and each '1' with the mask in R6 (usually n '1's). Thus for
  620. standard conversion you should set R6 to be 2^n-1 (=2^(2^R7)-1). (NB if R7
  621. (=r_bpp) is zero then all you have to do is copy the bitmap. R7=0 is not
  622. supported by this call.
  623.  
  624.  Entry:        R1=redraw block (only r_charh is used to find the height of
  625.             the character in pixels).
  626.          R2=bytes per cache line for the source character (1,2,*4)
  627.          R3=bytes per cache line for the dest character (1,2,*4)
  628.          R4=pointer to source character bitmap
  629.          R5=address to place destination character bitmap
  630.          R6=bit mask to insert in place of 1's (only bottom 2^R7 bits)
  631.          R7=Log_2 of number of bits per pixel (1-5)
  632.  
  633.  Exit:        R4 and R5 updated to the start of the 'next' characters.
  634.          R0 and flags corrupted.
  635.  
  636. ZapRedraw_CreatePalette (+&0A)
  637. ------------------------------
  638.  
  639. This SWI is used to create the r_palette data block. If R0=1 on entry then it
  640. takes a palette consisting of a list of wimp colour numbers (one per word)
  641. and converts it to entries of the form &BBGGRRxx, a 24 bit palette entry by
  642. using the call Wimp_ReadPalette and duplicating the nibbles. If R0=2 on entry
  643. then it takes a list of entries of the form &BBGGRRxx and converts them to
  644. colour masks required for DSA redraw (see r_palette) using ColourTrans calls
  645. and ZapRedraw_GetPaletteEntry. If R0=3 on entry then it does both, converting
  646. wimp colour numbers to DSA redraw masks.
  647.  
  648.  Entry:        R0=reason code:
  649.              b0 Set to convert wimp cols to &BBGGRRxx
  650.              b1 Set to convert &bbggrrxx to DSA colour masks
  651.              b2+ reserved - set to 0
  652.          R1=redraw block. The following are used:
  653.             r_bpp      = log_2 of bits per pixel
  654.             r_workarea = pointer to 128 byte work area to load wimp
  655.                     palette into.
  656.         R2=address of source palette
  657.         R3=address for dest palette (needs 4*R4 bytes preserved)
  658.            (source may equal destination)
  659.         R4=number of palette entries (eg 16)
  660.  
  661.  Exit:        R0 and flags corrupted.
  662.  
  663. ZapRedraw_InsertChar (+&0B)
  664. ---------------------------
  665.  
  666. This inserts a single character into a string of r_data format. If R0=0 then
  667. it inserts 0,0 and if R0>=&100 then it inserts 0,3,x,y where R0=&yyxx.
  668. Otherwise it just inserts the byte as normal.
  669.  
  670.  Entry:        R0=character
  671.          R1=string address
  672.          
  673.  Exit:        R1 updated 'till after the character
  674.          R0 and flags corrupted.
  675.  
  676. ZapRedraw_ReadSystemChars (+&0C)
  677. --------------------------------
  678.  
  679. This reads the standard system characters bitmaps via OS_Word calls. It reads
  680. them in 1 bit per pixel (8 bytes per character) form suitable for
  681. ZapRedraw_ConvertBitmap to convert it to a form usable for
  682. ZapRedraw_RedrawArea. To do this, it just bit-reverses the information read
  683. by OS_Word,10. It only reads characters &20-&FF, leaving 0-&1F untouched. The
  684. bit reversing is done efficiently so this call is fairly fast.
  685.  
  686.  Entry:        R0=buffer for bitmap (size 8*256=&800=2k)
  687.          R1=redraw block. r_workarea must be a 16 byte work area.
  688.          
  689.  Exit:        R0 and flags corrupted.
  690.  
  691. ZapRedraw_ReverseBitmaps (+&0D)
  692. -------------------------------
  693.  
  694. This SWI takes a list of bytes and reverses the bits of each byte. This is
  695. useful for reversing the bitmaps (flipping about the y axis) of 8*8 pixel
  696. characters at one bit per pixel (ie r_cbpl=1 r_cbpc=8).
  697.  
  698.  Entry:        R1=source buffer
  699.          R2=destination buffer (can equal source)
  700.          R3=number of bytes (must be a multiple of 4)
  701.  
  702.  Exit:        R0 and flags corrupted.
  703.  
  704. ZapRedraw_ReadVduVars (+&0E)
  705. ----------------------------
  706.  
  707. This SWI is used to set up the Zap redraw block initially. It puts the value
  708. 0 in r_screen so the actual screen address is used when ZapRedraw_RedrawArea
  709. is called (this can change quite often) and fills in r_bpl, r_bpp, r_magx,
  710. r_magy, r_xsize, r_ysize by using the call OS_ReadVduVariables. It also fills
  711. in r_mode by using OS_Byte 135. This call should be made after any mode
  712. change. Compensation is made for double pixel modes by decreasing r_magx. A
  713. pixel in Zap means a hardware pixel rather than an emulated double pixel.
  714.  
  715.  Entry:        R1=redraw block to update
  716.             r_workarea should point to a 64 byte scratch area.
  717.  
  718.  Exit:        R0 and flags corrupted.
  719.  
  720. ZapRedraw_GetRectangle (+&0F)
  721. -----------------------------
  722.  
  723. This SWI should be used after calls to Wimp_GetRectangle. It takes the redraw
  724. rectangle block as returned by Wimp_RedrawWindow or Wimp_GetRectangle and
  725. uses it to fill in the ZapRedraw block. The scroll offsets of the update
  726. rectangle are in pixels. The y scroll offset is the amount 'down' from the
  727. work area origin (inclusive), so negating will get the 'upward' scroll
  728. offset in pixels (exclusive), and the shifting by r_magy will give the
  729. normal OS work area scroll offset (which is exclusive).
  730.  
  731.  Entry:        R0=block as returned by Wimp_RedrawWindow/Wimp_GetRectangle
  732.             ie: window handle,minx,miny,maxx,maxy,scrollx,scrolly etc
  733.          R1=Zap redraw block with r_magx,r_magy,r_xsize,r_ysize
  734.             filled in.
  735.  
  736.  Exit:        r_minx,r_miny,r_maxx,r_maxy,r_scrollx,r_scrolly have been
  737.          filled in in the redraw block pointed to by R1.
  738.          R0 and flags corrupted.
  739.  
  740. ZapRedraw_AddVduBitmaps (+&10)
  741. ------------------------------
  742.  
  743. If you look at the VDU codes, you will see that characters 0-&1F,&7F,&100+
  744. are treated specially during a VDU redraw, drawing blocks and squares. The
  745. purpose of this SWI is to create bitmaps for these extra characters from a
  746. standard bitmap of the normal characters, so you can also use these in a DSA
  747. redraw. You specify an interval of characters, and in that interval, it
  748. creates bitmaps for the following:
  749.  
  750.     &00    Creates bitmap for '0' by copying bitmap &30
  751.     &01-&1F Creates bitmap for 'AB...' by copying bitmaps &41-&5F
  752.     &7F    Creates a filled in square.
  753.     &100    Top bottom and left edge filled [
  754.     &101    Top and bottom edges
  755.     &102    Top bottom and right edge filled ]
  756.     &103    Empty square
  757.     &104    Underscore _
  758.     &105    Left edge (giving a bar)
  759.     &106+    Undefined (currently copies the @ character).
  760.     
  761. This means that the bitmaps will then be consistent with the VDU characters
  762. of these numbers. These bitmaps are also useful as cursors.
  763.  
  764.  Entry: R1=redraw block (uses r_charw and r_charh to find the char size)
  765.         r_workarea must have 64 bytes + room for a character sprite
  766.         (see ZapRedraw_SpriteSize) reserved.
  767.         R2=first extra bitmap to create (eg 0)
  768.         R3=last extra bitmap to create (inclusive eg &104)
  769.         R4=address of bitmaps in 1 bit per pixel form.
  770.            (space must be reserved for the characters to be created).
  771.  
  772.  Exit:    R0 and flags corrupted.
  773.  
  774. ZapRedraw_CacheFontChars (+&11)
  775. -------------------------------
  776.  
  777. This SWI takes an anti-aliased font and caches a range of characters as
  778. bitmaps (see r_caddr). The cacheing can be done in any colours or screen
  779. resolution. Of course only those with foreground colour all bits set and
  780. background colour all bits clear can be used directly by
  781. ZapRedraw_RedrawArea. However, by giving a foreground colour mask of -1 and a
  782. background mask of 0 any bitmap can be drawn (see r_caddr etc). An hourglass
  783. is given with the % as the current character/256 if it takes a long time.
  784.  
  785.  Entry:    R0=reason code and other registers as below.
  786.            
  787.   R0=1 => Cache font in current wimp mode (ie wimp palette used).
  788.         R1=redraw block with the following set up:
  789.         r_bpp = number of bits per pixel to cache at
  790.         r_caddr = address of cache with space reserved for the chars
  791.         r_cbpl/cbpc/r_charw/r_charh setup
  792.         r_for/r_bac = offset in r_palette of for and bac cols
  793.         r_palette = palette of colours as for VDU redraw mode
  794.                 (ie each entry of form &BBGGRRxx)
  795.         r_workarea = room for 64 bytes + single sprite
  796.                  (use ZapRedraw_SpriteSize).
  797.         r_mode = mode to cache font in (ie mode sprite defined in).
  798.       R2=pointer to font name
  799.       R3=font size to plot at (points)
  800.       R4=x os offset (from bottom left) to plot character in the box
  801.       R5=y os offset (from bottom left) to plot character in the box
  802.       R6=first character to cache (0 caches as &30 and 1-&1F have &40
  803.          added &7F is ignored).
  804.       R7=last character to cache (inclusive)
  805.  
  806.   R0=2 => Cache font in mode 0 with background 0 and foreground 1.
  807.       R1=redraw block with the following set up:
  808.           r_caddr = address of cache with space reserved for the chars
  809.           r_cbpl/cbpc/r_charw/r_charh setup
  810.           r_workarea = as for R0=1
  811.           r_magx,r_magy for mode used with reason code R0=1
  812.       R2-R7 as for reason code R0=1.
  813.       Font size is scaled up by 2^(1-r_magx) horizontally and
  814.       2^(2-r_magy) vertically so the characters are the same pixel
  815.       size as those cached with R0=1.
  816.       
  817.  Exit: R0 and flags corrupted.
  818.  
  819. ZapRedraw_SpriteSize (+&12)
  820. ---------------------------
  821.  
  822. Several SWI's (eg ZapRedraw_RedrawArea - VDU mode, ZapRedraw_CacheFontChars)
  823. need to create a sprite area the size of a single character. This call
  824. returns the size required for this sprite (+palette+mask+save area etc), and
  825. thus the amount of workarea that should be reserved. The sprite needs a save
  826. area as it appears that Font_Paint redirects output to a sprite and thus
  827. corrupts the graphics colours. This means that it takes two passes to read
  828. the size required for the sprite - the first to read the size for the sprite
  829. and the second to create the sprite (space now reserved for it) and calculate
  830. the save area required via OS_SpriteOp,62.
  831.  
  832.  Example: SYS "ZapRedraw_SpriteSize",&01,redraw_block TO size%
  833.        PROCensure_workarea(size%)
  834.        SYS "ZapRedraw_SpriteSize",&81,redraw_block TO size%
  835.        PROCensure_workarea(size%)
  836.  (NB In practice the SWI usually requires 64+size% bytes of workspace)
  837.  
  838.  Entry:    R0=reason code
  839.         b0-b6 1=return sprite size for sprite in current mode and r_bpp
  840.               2=return sprite size for a mode 0 sprite (ie assume r_bpp=0)
  841.         b7    Clear for first pass, set for second pass.
  842.      R1=redraw block with r_bpp,r_charw,r_charh setup.
  843.         On the second pass r_workarea must be at least the size returned
  844.         by the first pass.
  845.      
  846.  Exit:  On first pass : R0=size required for sprite area (no save area).
  847.      On second pass: R0=total size required for sprite + save area.
  848.  
  849. ZapRedraw_RedrawWindow (+&13)
  850. -----------------------------
  851.  
  852. This SWI performs the calls to Wimp_RedrawWindow, Wimp_GetRectangle,
  853. Zap_GetRectangle, and Zap_RedrawArea for you. It assumes that the redraw
  854. block is already setup. This call is equivalent to the basic code:
  855.     SYS "Wimp_RedrawWindow",,data% TO flag%
  856.         WHILE flag%
  857.          SYS "ZapRedraw_GetRectangle",data%,redraw%
  858.          SYS "ZapRedraw_RedrawArea",,redraw%
  859.          SYS "Wimp_GetRectangle",,data% TO flag%
  860.         ENDWHILE
  861. where redraw% is the address of the redraw block and data% the data block
  862. returned by Wimp_Poll for event 1 (redraw window request).
  863.  
  864.  Entry:    R0=Redraw block as returned by Wimp for Wimp_Poll 1 (data%)
  865.      R1=Zap redraw block with r_data containing the text to redraw. All
  866.         of the block should be setup apart from rectangle to draw
  867.         and the scroll offsets which are filled in for you.
  868.         
  869.  Exit:    R0 and flags corrupted.
  870.